package com.wanmait.myhouse.mediatorController;

import com.wanmait.myhouse.dao.FeedBackDAO;
import com.wanmait.myhouse.dao.MediatorFeedDAO;
import com.wanmait.myhouse.vo.FeedBack;
import com.wanmait.myhouse.vo.MediatorFeed;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Controller
@RequestMapping("mediator")
public class ContactController {
    @GetMapping("contact")
    public String contact(){
        return "mediator/contact";
    }

    @PostMapping("mediatorFeedBack")
    public String mediatorFeedBack(MediatorFeed mediatorFeed){
        MediatorFeedDAO mediatorFeedDAO = new MediatorFeedDAO();
        mediatorFeed.setDispose(false);
        LocalDateTime localDateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        Timestamp time = Timestamp.valueOf(localDateTime.format(formatter));
        mediatorFeed.setTime(time);
        mediatorFeedDAO.addMediatorFeed(mediatorFeed);
        return "redirect:/mediator/contact";
    }
}
